<template>
  <div class="vote-apply">
    <group>
      <cell title="投票主题：">{{voteTitle}}</cell>
      <cell title="主题ID：">{{voteId}}</cell>
      <x-input title="申请人：" :max="20" v-model="userTrueName" placeholder="请输入姓名"></x-input>
    </group>
    <div style="height: .42rem;"></div>
    <group>
      <x-input title="申请口令：" :max="50" v-model="applyWord" placeholder="请输入申请口令...."></x-input>
    </group>
    <div class="btn-commit" @click="handleClickCommit">提交</div>
  </div>
</template>

<script>
  import { Group, Cell, XInput } from 'vux'
  import {parseUrlParams} from "../../util";
  let CONSTANT = require('../../../wechat/static/constant/constant.js'),
    common = require("../../../wechat/static/common/common.js"),
    wsService = require("../../../wechat/static/common/wechat-jsdk.js");

  export default {
    components: {
      Group, Cell, XInput
    },
    data () {
      return {
        voteId: "",
        userTrueName: "",
        applyWord: "",
        voteTitle: ""
      }
    },
    mounted(){
      this.voteId = parseUrlParams("id");
      this.voteTitle = decodeURIComponent(parseUrlParams("title"));
    },
    methods:{
      handleClickCommit() {
        if(!this.userTrueName) {
          this.$vux.alert.show({
            title: "提示",
            content: "请输入申请人姓名",
            onShow () {

            },
            onHide () {
            }
          })
          return false;
        }
        if(!this.applyWord) {
          this.$vux.alert.show({
            title: "提示",
            content: "请输入申请口令",
            onShow () {

            },
            onHide () {
            }
          })
          return false;
        }

        let params = {
          voteId: this.voteId,
          userTrueName: this.userTrueName,
          applyWord: this.applyWord,
        }
        common.requestAjax(CONSTANT.URL.APPLY.APPLY, params, {}, (res) => {
          if (res.status == 200) {
            this.$router.push("/check")
//            this.$vux.alert.show({
//              title: "提示",
//              content: res.msg,
//              onShow () {
//
//              },
//              onHide () {
//              }
//            })
          }
        })
      }
    },
  }
</script>

<style lang="scss">
  .vote-apply {
    font-size: .3rem;
    background-color: #f2f2f2;
    height: 100%;
    padding-top: .3rem;
    .weui-cells {
      font-size: .32rem!important;
      color: #333;
    }
    .weui-cells, .vux-no-group-title {
      margin-top: 0!important;
    }
    .weui-cell__ft, .vux-cell-bd {
      white-space: nowrap!important;
    }
    .btn-commit {
      width: 5.48rem;;
      height: .88rem;
      line-height: .88rem;
      text-align: center;
      color: #fff;
      background: #198AE7;
      border-radius: .1rem;
      margin-left: 1.01rem;
      margin-top: 1.89rem;
    }
  }
</style>
